



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package randomimages;


import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.geom.*;
import java.net.*;



/**
 *
 * @author shohdi
 */
public class RandomImages extends JFrame {
    
    private Image image;
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new RandomImages();
        // TODO code application logic here
    }
    
    
    public RandomImages()
    {
        super("Random Images");
        setSize(600,500);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        Toolkit tk = Toolkit.getDefaultToolkit();
        image = tk.getImage(getURL("spaceship.png"));
        
    }
    
    
    AffineTransform identity = new AffineTransform();
    
    private URL getURL (String filename)
    {
        URL url = null;
        try{
            url = this.getClass().getResource(filename);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        
        return url;
            
    }
    
    
    public void paint(Graphics g)
    {
        Graphics2D g2d = (Graphics2D)g;
        
        AffineTransform trans = new AffineTransform();
        
        Random rand = new Random();
        
        int width = getSize().width;
        int height = getSize().height;
        
        g2d.setColor(Color.BLACK);
        
        g2d.fillRect(0, 0, getSize().width, getSize().height);
        
        for (int n=0;n<50;n++)
        {
            trans.setTransform(identity);
            
            trans.translate(rand.nextInt()%width, rand.nextInt()%height);
            
            trans.rotate(Math.toRadians(360 * rand.nextDouble()));
            double scale = 0.25 * (rand.nextDouble()+1);
            trans.scale(scale, scale);
            g2d.drawImage(image, trans, this);
            
            
        }
    }
}
